

def return_to(req_context):
    redirect_to(req_context, ref_site(req_context))

def redirect_to(req_context, url):
    req_context.status = '302 Found'
    header(req_context, 'Location', url)

def header(req_context, k, v):
    headers = req_context.headers
    headers.append((k, v))
    
def ref_site(req_context):
    environ = req_context.environ
    
    return environ.has_key('HTTP_REFERER') and environ['HTTP_REFERER'] or ''